package com.example.demo1104.demo3;

import java.util.ArrayList;
import java.util.List;

public class Test04 {

    public static void main(String[] args) {

        List<Animal> animal=new ArrayList<>();
        animal.add(new Animal("野猪佩奇",18,'F',"猪"));
        animal.add(new Animal("野猪乔治",20,'F',"猫"));
        animal.add(new Animal("杨幂",20,'M',"狼"));
        animal.add(new Animal("杨超越",19,'M',"羊"));
        animal.add(new Animal("薛之谦",27,'F',"猪"));

        animal.stream().filter(item-> {
           return item.getAge() > 20;
        }).forEach(item-> System.out.println(item));


        long count = animal.stream().filter(item -> item.getKind().equals("猪")).count();
        System.out.println(count);

    }


}
class Animal{
    private String name;
    private Integer age;
    private  char sex;
    private  String kind;

    public Animal(String name, Integer age, char sex, String kind) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.kind = kind;
    }


    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                ", kind='" + kind + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public String getKind() {
        return kind;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }
}